package com.douma._2022_7_7;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 抖码算法，让算法学习变的简单有趣
 *
 * @作者 : 老汤
 */
public class 快递运输 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String[] strs = sc.nextLine().split(",");
        int n = sc.nextInt();

        int len = strs.length;
        int[] nums = new int[len];
        for (int i = 0; i < len; i++) {
            nums[i] = Integer.valueOf(strs[i]);
        }

        // 对快递进行从小到大排序
        Arrays.sort(nums);
        int amt = 0;
        int res = 0;
        for (int i = 0; i < len; i++) {
            amt += nums[i];
            // 若大于载重量则退出循环
            if (amt > n) {
                break;
            }
            res++;
        }

        System.out.println(res);
    }
}
